package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseWarehouseLocation;
import com.sumi.erp.service.IBaseWarehouseLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 虚拟仓位Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/erp/location")
public class BaseWarehouseLocationController extends BaseController
{
    @Autowired
    private IBaseWarehouseLocationService baseWarehouseLocationService;

    /**
     * 查询虚拟仓位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseWarehouseLocation baseWarehouseLocation)
    {
        startPage();
        List<BaseWarehouseLocation> list = baseWarehouseLocationService.selectBaseWarehouseLocationList(baseWarehouseLocation);
        return getDataTable(list);
    }

    /**
     * 导出虚拟仓位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:location:export')")
    @Log(title = "虚拟仓位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseWarehouseLocation baseWarehouseLocation)
    {
        List<BaseWarehouseLocation> list = baseWarehouseLocationService.selectBaseWarehouseLocationList(baseWarehouseLocation);
        ExcelUtil<BaseWarehouseLocation> util = new ExcelUtil<BaseWarehouseLocation>(BaseWarehouseLocation.class);
        util.exportExcel(response, list, "虚拟仓位数据");
    }

    /**
     * 获取虚拟仓位详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseWarehouseLocationService.selectBaseWarehouseLocationById(id));
    }

    /**
     * 新增虚拟仓位
     */
    @PreAuthorize("@ss.hasPermi('erp:location:add')")
    @Log(title = "虚拟仓位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseWarehouseLocation baseWarehouseLocation)
    {
        return toAjax(baseWarehouseLocationService.insertBaseWarehouseLocation(baseWarehouseLocation));
    }

    /**
     * 修改虚拟仓位
     */
    @PreAuthorize("@ss.hasPermi('erp:location:edit')")
    @Log(title = "虚拟仓位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseWarehouseLocation baseWarehouseLocation)
    {
        return toAjax(baseWarehouseLocationService.updateBaseWarehouseLocation(baseWarehouseLocation));
    }

    /**
     * 删除虚拟仓位
     */
    @PreAuthorize("@ss.hasPermi('erp:location:remove')")
    @Log(title = "虚拟仓位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseWarehouseLocationService.deleteBaseWarehouseLocationByIds(ids));
    }
}
